<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>九宫格图表示例</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f7f7f7;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }
        .grid-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-template-rows: repeat(4, 1fr);
            gap: 20px;
            width: 90%;
            max-width: 1000px;
            max-height: 1200px;
        }
        .chartContainer {
            background-color: #ffffff;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            aspect-ratio: 1 / 1;
            overflow: hidden;
        }
        .chartContainer canvas {
            width: 100% !important;
            height: 100% !important;
        }
        .info-container {
            text-align: center;
            font-size: 16px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div class="grid-container">
    <div class="chartContainer"><canvas id="successRateChart"></canvas></div>
    <div class="chartContainer"><canvas id="multiLineChart"></canvas></div>
    <div class="chartContainer"><canvas id="integrationTimeCostChart"></canvas></div>
    <div class="chartContainer"><canvas id="otaSuccessRateChart"></canvas></div>
    <div class="chartContainer"><canvas id="releaseRateChart"></canvas></div>
    <div class="chartContainer"><canvas id="integrationSuccessChart"></canvas></div>
    <div class="chartContainer"><canvas id="integrationAccuracyChart"></canvas></div>
    <div class="chartContainer"><canvas id="periodFailureDistributionChart"></canvas></div>
    <div class="chartContainer"><canvas id="failureDistributionChart"></canvas></div>
    <div class="chartContainer"><canvas id="pipelineStatusChart"></canvas></div>
    <div class="chartContainer"><canvas id="activityRankingChart"></canvas></div>
    <div class="chartContainer"><canvas id="releaseFunnelChart"></canvas></div>
</div>

<!-- 时间单位选择菜单 -->
<div style="text-align: center; margin-bottom: 20px;">
    <label for="timeUnit">选择时间单位:</label>
    <select id="timeUnit">
        <option value="day">日</option>
        <option value="week">周</option>
        <option value="month" selected>月</option>
        <option value="quarter">季度</option>
        <option value="year">年</option>
    </select>
</div>

<script>
    // 定义不同时间单位的X轴标签数据
    const dataLabels = {
        day: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
        week: ['第1周', '第2周', '第3周', '第4周', '第5周'],
        month: ['8月', '9月', '10月', '11月', '12月'],
        quarter: ['Q1', 'Q2', 'Q3', 'Q4'],
        year: ['2020', '2021', '2022', '2023', '2024']
    };

    // 初始化图表对象数组
    const charts = [];

    // 初始化图表函数
    function initChart(chartId, chartType, data, options) {
        const ctx = document.getElementById(chartId).getContext('2d');
        const chart = new Chart(ctx, { type: chartType, data: data, options: options });
        charts.push(chart); // 添加到charts数组
        return chart;
    }

    // 初始化每个图表的数据和配置
    initChart('successRateChart', 'line', {
        labels: dataLabels.month,
        datasets: [{
            label: '发布成功率',
            data: [100, 100, 100, 100, 100],
            borderColor: '#FF7F50',
            backgroundColor: '#FF7F50',
            borderWidth: 2,
            fill: false,
            pointRadius: 6,
            pointBackgroundColor: '#FF7F50'
        }]
    }, {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            legend: { display: true, position: 'top' },
            title: { display: true, text: '发布成功率', font: { size: 16 } }
        },
        scales: {
            y: { beginAtZero: true, ticks: { callback: (value) => value + '%' } },
            x: { title: { display: true, text: '时间' } }
        }
    });

    initChart('multiLineChart', 'line', {
        labels: dataLabels.month,
        datasets: [
            { label: '模块软件发布', data: [80, 78, 75, 80, 82], borderColor: '#808080', backgroundColor: '#808080' },
            { label: 'C2软件发布', data: [70, 65, 68, 72, 69], borderColor: '#FF7F50', backgroundColor: '#FF7F50' },
            { label: '自动测试报告输出', data: [40, 38, 35, 37, 36], borderColor: '#90EE90', backgroundColor: '#90EE90' }
        ]
    }, {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            legend: { display: true, position: 'top' },
            title: { display: true, text: '冒烟准点率', font: { size: 16 } }
        },
        scales: {
            y: { beginAtZero: true, ticks: { callback: (value) => value + '%' } },
            x: { title: { display: true, text: '时间' } }
        }
    });

    initChart('otaSuccessRateChart', 'line', {
        labels: dataLabels.month,
        datasets: [{
            label: 'OTA成功率',
            data: [100, 95, 92, 88, 85],
            borderColor: '#FF7F50',
            backgroundColor: '#FF7F50',
            borderWidth: 2,
            fill: false,
            pointRadius: 6,
            pointBackgroundColor: '#FF7F50'
        }]
    }, {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            legend: { display: true, position: 'top' },
            title: { display: true, text: 'OTA成功率', font: { size: 16 } }
        },
        scales: {
            y: { beginAtZero: true, max: 100, ticks: { callback: (value) => value + '%' } },
            x: { title: { display: true, text: '时间' } }
        }
    });

    initChart('integrationTimeCostChart', 'bar', {
        labels: dataLabels.month,
        datasets: [{
            label: '发布的版本个数',
            data: [3, 4, 5, 3, 6],
            backgroundColor: '#42A5F5'
        }]
    }, {
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            legend: { display: true, position: 'top' },
            title: { display: true, text: '集成时间成本', font: { size: 16 } },
            tooltip: {
                callbacks: {
                    label: (context) => `累计人数: ${10 + context.dataIndex * 2}, 关联人数: ${5 + context.dataIndex}`
                }
            }
        },
        scales: { y: { beginAtZero: true, title: { display: true, text: '版本个数' } } }
    });

    // 集成失败问题分布饼图
    const ctx3 = document.getElementById('failureDistributionChart').getContext('2d');
    const failureDistributionChart = new Chart(ctx3, {
        type: 'pie',
        data: {
            labels: ['工具链', '集成', '产品线', '感知', '规控', '底软'],
            datasets: [{ data: [27, 6, 14, 27, 19, 7], backgroundColor: ['#B0C4DE', '#FFFF10', '#FF7F50', '#696969', '#9370DB', '#AFEEEE'] }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: true, position: 'top' },
                title: { display: true, text: '集成失败问题分布', font: { size: 16 } }
            }
        }
    });

    // 当天流水线运行情况图表
    const ctx5 = document.getElementById('pipelineStatusChart').getContext('2d');
    const pipelineStatusChart = new Chart(ctx5, {
        type: 'bar',
        data: {
            labels: ['E2E', 'C3B', 'C2M'],
            datasets: [
                { label: '实际完成版本', data: [2, 2, 3], backgroundColor: '#4682B4' },
                { label: '计划完成版本', data: [4, 5, 5], backgroundColor: '#D3D3D3' }
            ]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: true, position: 'top' },
                title: { display: true, text: '当天流水线运行情况', font: { size: 16 } }
            },
            scales: {
                x: { title: { display: true, text: '流水线名称' } },
                y: { beginAtZero: true, title: { display: true, text: '版本数量' } }
            }
        }
    });

 // 冒烟失败问题分布饼图数据和配置
 const ctxPeriodFailure = document.getElementById('periodFailureDistributionChart').getContext('2d');
    const periodFailureDistributionChart = new Chart(ctxPeriodFailure, {
        type: 'pie',
        data: {
            labels: ['工具链', '集成', '产品线', '感知', '规控', '底软'],
            datasets: [{
                data: [27, 6, 14, 27, 19, 7],
                backgroundColor: ['#B0C4DE', '#FFFF10', '#FF7F50', '#696969', '#9370DB', '#AFEEEE'],
                borderColor: '#ffffff',
                borderWidth: 1
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: true,
                    position: 'top'
                },
                title: {
                    display: true,
                    text: '冒烟失败问题分布',
                    font: { size: 16 }
                }
            }
        }
    });

    //释放成功率折线图
    initChart('releaseRateChart', 'line', {
        labels: dataLabels.month,
        datasets: [{
                label: '释放成功率',
                data: [100, 80, 75, 10, 65],
                borderColor: '#FF7F50',
                backgroundColor: '#FF7F50',
                borderWidth: 2,
                fill: false,
                pointRadius: 6,
                pointBackgroundColor: '#FF7F50',
                pointBorderColor: '#FF7F50',
                pointHoverRadius: 7
            }]
    }, {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: true, position: 'top' },
                title: { display: true, text: '释放成功率', font: { size: 16 } }
            },
            scales: {
                y: { beginAtZero: true, ticks: { callback: (value) => value + '%' } },
                x: { title: { display: true, text: '月份' } }
            }
        });

    //集成成功率折线图
    initChart('integrationSuccessChart', 'line', {
        labels: dataLabels.month,
        datasets:[
                { label: 'soc', data: [80, 78, 75, 80, 82], borderColor: '#808080', backgroundColor: '#808080' },
                { label: 'mcu', data: [70, 65, 68, 72, 69], borderColor: '#FF7F50', backgroundColor: '#FF7F50' },
                { label: 'sdk', data: [40, 38, 35, 37, 36], borderColor: '#90EE90', backgroundColor: '#90EE90' },
                { label: 'app', data: [33, 38, 39, 67, 96], borderColor: '#90EEFF', backgroundColor: '#90EEFF' }
            ]
    }, {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: true, position: 'top' },
                title: { display: true, text: '集成成功率', font: { size: 16 } }
            },
            scales: {
                y: { beginAtZero: true, ticks: { callback: (value) => value + '%' } },
                x: { title: { display: true, text: '月份' } }
            }
        });

    //集成准点率图表integrationAccuracyChart
    initChart('integrationAccuracyChart', 'line', {
        labels: dataLabels.month,
        datasets: [
            { label: '模块软件释放', data: [80, 78, 75, 80, 82], borderColor: '#808080', backgroundColor: '#808080' },
            { label: 'C2软件释放', data: [70, 65, 68, 72, 69], borderColor: '#FF7F50', backgroundColor: '#FF7F50' },
            { label: '自动化报告输出', data: [40, 38, 35, 37, 36], borderColor: '#90EE90', backgroundColor: '#90EE90' }
        ]
    },{
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: true, position: 'top' },
                title: { display: true, text: '集成准点率', font: { size: 16 } }
            },
            scales: {
                y: { beginAtZero: true, ticks: { callback: (value) => value + '%' } },
                x: { title: { display: true, text: '月份' } }
            }
        });

    //代码提交活跃排行榜
    const rankingLabels = ['TOP1', 'TOP2', 'TOP3', 'TOP4', 'TOP5', 'TOP6', 'TOP7', 'TOP8', 'TOP9', 'TOP10'];
    const commitCounts = [30, 28, 26, 24, 22, 20, 18, 16, 14, 12];

    const activityRanking = document.getElementById('activityRankingChart').getContext('2d');
    const activityRankingChart = new Chart(activityRanking, {
        type: 'bar',
        data: {
            labels: rankingLabels,
            datasets: [{
                label: '代码提交次数',
                data: commitCounts,
                backgroundColor: '#9E99C9',
                borderRadius: 5,
                barThickness: 10,
            }]
        },
        options: {
            indexAxis: 'y',
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: false
                },
                title: {
                    display: true,
                    text: '代码提交活跃排行榜',
                    font: {
                        size: 16
                    }
                },
                tooltip: {
                    callbacks: {
                        label: function(context) {
                            return `提交次数: ${context.raw}`;
                        }
                    }
                }
            },
            scales: {
                x: {
                    beginAtZero: true,
                    max: 40,
                    title: {
                        display: true,
                        text: '提交次数'
                    }
                },
                y: {
                    title: {
                        display: true,
                        text: 'TOP排名'
                    }
                }
            }
        }
    });

    // 漏斗图数据定义
    const funnelLabels = ['计划版本数', '释放版本数', '发布版本数'];
    const funnelData = [45, 40, 37];

    const ctx6 = document.getElementById('releaseFunnelChart').getContext('2d');
    const releaseFunnelChart = new Chart(ctx6, {
        type: 'bar',
        data: {
            labels: funnelLabels,
            datasets: [{
                label: '版本数量',
                data: funnelData,
                backgroundColor: ['#A0D8E8', '#9E99C9', '#7D7D7D'],
            }]
        },
        options: {
            indexAxis: 'y',
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    display: false
                },
                title: {
                    display: true,
                    text: '发布情况总览',
                    font: {
                        size: 16
                    }
                },
                tooltip: {
                    callbacks: {
                        label: function(context) {
                            return `${context.label}：${context.raw}`;
                        }
                    }
                }
            },
            scales: {
                x: {
                    beginAtZero: true,
                    title: {
                        display: true,
                        text: '版本数量'
                    }
                },
                y: {
                    title: {
                        display: true,
                        text: ''
                    },
                    grid: {
                        display: false
                    }
                }
            }
        }
    });
    // 监听时间单位选择变化
    document.getElementById('timeUnit').addEventListener('change', function() {
        const selectedUnit = this.value;
        charts.forEach(chart => {
            chart.data.labels = dataLabels[selectedUnit]; // 更新X轴标签
            chart.update(); // 更新图表
        });
    });
</script>
</body>
</html>
